package hihocode;

import java.util.Scanner;

//一面砌墙
//https://hihocoder.com/problemset/problem/1494

public class CrossWall {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int floor;
		int[] map = new int[100000];
		while(scanner.hasNext()){
			floor = scanner.nextInt();
			int width = 0;
			for (int i = 0; i < floor; i++) {
				int curBlocks = scanner.nextInt();
				int lastWidth = 0;
				for(int j = 0; j < curBlocks; j++){
					int curWidth = scanner.nextInt();
					map[curWidth + lastWidth]++;
					lastWidth += curWidth;
				}
				//还要排除右边界
				map[lastWidth] = 0;
				width = lastWidth;
//				System.out.println("width :" + width);
			}
			
			int max = 0;
			for (int i = 0; i < width; i++) {
				max = Math.max(max, map[i]);
			}
			System.out.println(floor - max);
		}
		scanner.close();
	}
}
